package com.hmp.recruit.admin.sys.user.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hmp.recruit.admin.sys.user.dao.UserDao;
import com.hmp.recruit.admin.sys.user.service.UserService;
import com.hmp.recruit.admin.sys.user.vo.UserVo;
import com.hmp.recruit.common.util.config.AppProp;
import com.hmp.recruit.common.util.security.AESUtil;

@Service
public class UserServiceImpl implements UserService {
	
	@Resource
	private UserDao userDao;
	
	@Override
	public UserVo login(String email, String password) {
		String securityKey = AESUtil.parseByte2HexStr(AESUtil.enCrypt(email + password, AppProp.get("app.securityKey")));
		String dbPassword = AESUtil.parseByte2HexStr(AESUtil.enCrypt(password, securityKey));
		return userDao.login(email, dbPassword, securityKey);
	}

	@Override
	public void register(String email, String password) {
		UserVo userVo = new UserVo();
		userVo.setEmail(email);
		String securityKey = AESUtil.parseByte2HexStr(AESUtil.enCrypt(email + password, AppProp.get("app.securityKey")));
		userVo.setSecurityKey(securityKey);
		userVo.setPassword(AESUtil.parseByte2HexStr(AESUtil.enCrypt(password, securityKey)));
		userDao.register(userVo);
	}

	@Override
	public void validateEmail(String email) {
		userDao.validateEmail(email);
	}

	@Override
	public UserVo getByEmail(String email) {
		return userDao.getByEmail(email);
	}

	@Override
	public UserVo getById(String id) {
		return userDao.getById(id);
	}

	@Override
	public void update(UserVo user) {
		userDao.update(user);
	}

	@Override
	public void modifyPassword(String id, String newDbPassword, String securityKey) {
		userDao.modifyPassword(id, newDbPassword, securityKey);
	}

}
